var system = null;

function startSystem() {
    system = new Exit66JukeboxAdmin(document.getElementById('navbar'),
    document.getElementById('mainarea'));
}

function resizeSystem() {
    system.resize();
}

function Exit66JukeboxAdmin(oNav, oMain) {
    this._navContainer = oNav;
    this._mainContainer = oMain;
    
    this._navTable = null;
    
    this._panelControlCenter = null;
    this._panelLibraries = null;
    this._panelPlaylists = null;
    this._panelCompilations = null;
    this._panelEditDatabase = null;
        
    this._init();
    
    this.resize();
}

Exit66JukeboxAdmin.prototype._init = function() {
    var oThis = this;
    
    var columnDetails = new Array({className: 'menuItem'}, 
        {className: 'menuItem'}, {className: 'menuItem'}, 
        {className: 'menuItem'}, {className: 'menuItem'},
        {className: 'menuItem'});

    this._navTable = new Exit66Table('nav', columnDetails);
    
    var controlCenterFunction = function() {
        oThis._startControlCenter();
    }
    var libraryFunction = function() {
        oThis._startLibraries();
    }
    var playlistFunction = function() {
        oThis._startPlaylists();
    }
    var compliationFunction = function() {
        oThis._startCompliations();
    }
    var editDatabaseFunction = function() {
        oThis._startEditDatabase();
    }
    var exitAdminFunction = function() {
        oThis._exitAdminMenu();
    }
    
    this._navTable.addRow(new Array(
        {value: 'Control Center', clickFunction: controlCenterFunction}, 
        {value: 'Libraries', clickFunction: libraryFunction}, 
        {value: 'Playlists', clickFunction: playlistFunction}, 
        {value: 'Compilations', clickFunction: compliationFunction}, 
        {value: 'Edit Database', clickFunction: editDatabaseFunction}, 
        {value: 'Exit Admin Mode', clickFunction: exitAdminFunction}), null,
        'menuItem', true);
    this._navTable.addToParent(this._navContainer);
    
    this._startControlCenter();
    
}

Exit66JukeboxAdmin.prototype.resize = function() {
    if (this._panelControlCenter.hasParent()) {
        this._panelControlCenter.setHeight(document.body.clientHeight - 
            (this._navContainer.clientHeight) - 6);
    }
    if ((this._panelLibraries) && (this._panelLibraries.hasParent())) {
        this._panelLibraries.setHeight(document.body.clientHeight - 
            (this._navContainer.clientHeight) - 6);
    }
    if ((this._panelPlaylists) && (this._panelPlaylists.hasParent())) {
        this._panelPlaylists.setHeight(document.body.clientHeight - 
            (this._navContainer.clientHeight) - 6);
    }
    if ((this._panelCompilations) && (this._panelCompilations.hasParent())) {
        this._panelCompilations.setHeight(document.body.clientHeight - 
            (this._navContainer.clientHeight) - 6);
    }
    if ((this._panelEditDatabase) && (this._panelEditDatabase.hasParent())) {
        this._panelEditDatabase.setHeight(document.body.clientHeight - 
            (this._navContainer.clientHeight) - 6);
    }
}

Exit66JukeboxAdmin.prototype._makeInvisible = function(exceptPanel) {
    if ((exceptPanel != this._panelControlCenter) && (this._panelControlCenter))
        this._panelControlCenter.removeFromParent();
    if ((exceptPanel != this._panelLibraries) && (this._panelLibraries))
        this._panelLibraries.removeFromParent();
    if ((exceptPanel != this._panelPlaylists) && (this._panelPlaylists))
        this._panelPlaylists.removeFromParent();
    if ((exceptPanel != this._panelCompilations) && (this._panelCompilations))
        this._panelCompilations.removeFromParent();
    if ((exceptPanel != this._panelEditDatabase) && (this._panelEditDatabase))
        this._panelEditDatabase.removeFromParent();
}

Exit66JukeboxAdmin.prototype._startControlCenter = function() {
    if (!this._panelControlCenter) {
        this._panelControlCenter = new Exit66RoundedBox('adminPanel');
        label = document.createElement('div');
        label.className = 'header';
        label.appendChild(document.createTextNode('Control Center'));
        this._panelControlCenter.addToContent(label);
    }
    this._makeInvisible(this._panelControlCenter);
    this._panelControlCenter.addToParent(this._mainContainer);
    this.resize();
}

Exit66JukeboxAdmin.prototype._startLibraries = function() {
    if (!this._panelLibraries) {
        this._panelLibraries = new Exit66RoundedBox('adminPanel');
        label = document.createElement('div');
        label.className = 'header';
        label.appendChild(document.createTextNode('Libraries'));
        this._panelLibraries.addToContent(label);
    }
    this._makeInvisible(this._panelLibraries);
    this._panelLibraries.addToParent(this._mainContainer);
    this.resize();
}

Exit66JukeboxAdmin.prototype._startPlaylists = function() {
    if (!this._panelPlaylists) {
        this._panelPlaylists = new Exit66RoundedBox('adminPanel');
        label = document.createElement('div');
        label.className = 'header';
        label.appendChild(document.createTextNode('Playlists'));
        this._panelPlaylists.addToContent(label);
    }
    this._makeInvisible(this._panelPlaylists);
    this._panelPlaylists.addToParent(this._mainContainer);
    this.resize();
}

Exit66JukeboxAdmin.prototype._startCompliations = function() {
    if (!this._panelCompilations) {
        this._panelCompilations = new Exit66RoundedBox('adminPanel');
        label = document.createElement('div');
        label.className = 'header';
        label.appendChild(document.createTextNode('Compilations'));
        this._panelCompilations.addToContent(label);
    }
    this._makeInvisible(this._panelCompilations);
    this._panelCompilations.addToParent(this._mainContainer);
    this.resize();
}

Exit66JukeboxAdmin.prototype._startEditDatabase = function() {
    if (!this._panelEditDatabase) {
        this._panelEditDatabase = new Exit66RoundedBox('adminPanel');
        label = document.createElement('div');
        label.className = 'header';
        label.appendChild(document.createTextNode('Edit Database'));
        this._panelEditDatabase.addToContent(label);
    }
    this._makeInvisible(this._panelEditDatabase);
    this._panelEditDatabase.addToParent(this._mainContainer);
    this.resize();
}

Exit66JukeboxAdmin.prototype._exitAdminMenu = function() {
    alert('Control Center');
}
function getXmlResponseNode(xml) {
    var node = xml.firstChild;
    while (node) {
        if (node.tagName == 'response') {
            return node;
        }
        node = node.nextSibling;
    }
}

function getNodeText(node) {
    if (window.ActiveXObject) {
        return node.text;
    }
    else if (navigator.userAgent.toLowerCase().indexOf("opera") > -1) {
        return node.innerText;
    }
    else {
        return node.textContent;
    }
}
